|
1
|
|
|
import React from 'react'; |
|
2
|
|
|
import { Route, Switch } from 'react-router-dom'; |
|
3
|
|
|
import Swipeable from 'react-swipeable'; |
|
4
|
|
|
import { faBars as burgerIcon } from '@fortawesome/free-solid-svg-icons'; |
|
5
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; |
|
6
|
|
|
import classnames from 'classnames'; |
|
7
|
|
|
import * as PropTypes from 'prop-types'; |
|
8
|
|
|
import { serverType } from '../servers/prop-types'; |
|
9
|
|
|
import NotFound from './NotFound'; |
|
10
|
|
|
import './MenuLayout.scss'; |
|
11
|
|
|
|
|
12
|
|
|
const MenuLayout = (TagsList, ShortUrls, AsideMenu, CreateShortUrl, ShortUrlVisits) => |
|
13
|
|
|
class MenuLayout extends React.Component { |
|
14
|
|
|
static propTypes = { |
|
15
|
|
|
match: PropTypes.object, |
|
16
|
|
|
selectServer: PropTypes.func, |
|
17
|
|
|
location: PropTypes.object, |
|
18
|
|
|
selectedServer: serverType, |
|
19
|
|
|
}; |
|
20
|
|
|
|
|
21
|
|
|
state = { showSideBar: false }; |
|
22
|
|
|
|
|
23
|
|
|
componentDidMount() { |
|
24
|
|
|
const { match, selectServer } = this.props; |
|
25
|
|
|
const { params: { serverId } } = match; |
|
26
|
|
|
|
|
27
|
|
|
selectServer(serverId); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
componentDidUpdate(prevProps) { |
|
31
|
|
|
const { location } = this.props; |
|
32
|
|
|
|
|
33
|
|
|
// Hide sidebar when location changes |
|
34
|
2 |
|
if (location !== prevProps.location) { |
|
35
|
|
|
this.setState({ showSideBar: false }); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
render() { |
|
40
|
|
|
const { selectedServer, match } = this.props; |
|
41
|
|
|
const { params: { serverId } } = match; |
|
42
|
|
|
const burgerClasses = classnames('menu-layout__burger-icon', { |
|
43
|
|
|
'menu-layout__burger-icon--active': this.state.showSideBar, |
|
44
|
|
|
}); |
|
45
|
|
|
const swipeMenuIfNoModalExists = (showSideBar) => () => { |
|
46
|
2 |
|
if (document.querySelector('.modal')) { |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
this.setState({ showSideBar }); |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
return ( |
|
54
|
|
|
<React.Fragment> |
|
55
|
|
|
<FontAwesomeIcon |
|
56
|
|
|
icon={burgerIcon} |
|
57
|
|
|
className={burgerClasses} |
|
58
|
|
|
onClick={() => this.setState(({ showSideBar }) => ({ showSideBar: !showSideBar }))} |
|
59
|
|
|
/> |
|
60
|
|
|
|
|
61
|
|
|
<Swipeable |
|
62
|
|
|
delta={40} |
|
63
|
|
|
className="menu-layout__swipeable" |
|
64
|
|
|
onSwipedLeft={swipeMenuIfNoModalExists(false)} |
|
65
|
|
|
onSwipedRight={swipeMenuIfNoModalExists(true)} |
|
66
|
|
|
> |
|
67
|
|
|
<div className="row menu-layout__swipeable-inner"> |
|
68
|
|
|
<AsideMenu |
|
69
|
|
|
className="col-lg-2 col-md-3" |
|
70
|
|
|
selectedServer={selectedServer} |
|
71
|
|
|
showOnMobile={this.state.showSideBar} |
|
72
|
|
|
/> |
|
73
|
|
|
<div |
|
74
|
|
|
className="col-lg-10 offset-lg-2 col-md-9 offset-md-3" |
|
75
|
|
|
onClick={() => this.setState({ showSideBar: false })} |
|
76
|
|
|
> |
|
77
|
|
|
<Switch> |
|
78
|
|
|
<Route |
|
79
|
|
|
exact |
|
80
|
|
|
path="/server/:serverId/list-short-urls/:page" |
|
81
|
|
|
component={ShortUrls} |
|
82
|
|
|
/> |
|
83
|
|
|
<Route |
|
84
|
|
|
exact |
|
85
|
|
|
path="/server/:serverId/create-short-url" |
|
86
|
|
|
component={CreateShortUrl} |
|
87
|
|
|
/> |
|
88
|
|
|
<Route |
|
89
|
|
|
exact |
|
90
|
|
|
path="/server/:serverId/short-code/:shortCode/visits" |
|
91
|
|
|
component={ShortUrlVisits} |
|
92
|
|
|
/> |
|
93
|
|
|
<Route |
|
94
|
|
|
exact |
|
95
|
|
|
path="/server/:serverId/manage-tags" |
|
96
|
|
|
component={TagsList} |
|
97
|
|
|
/> |
|
98
|
|
|
<Route |
|
99
|
|
|
render={() => <NotFound to={`/server/${serverId}/list-short-urls/1`} btnText="List short URLs" />} |
|
100
|
|
|
/> |
|
101
|
|
|
</Switch> |
|
102
|
|
|
</div> |
|
103
|
|
|
</div> |
|
104
|
|
|
</Swipeable> |
|
105
|
|
|
</React.Fragment> |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
}; |
|
109
|
|
|
|
|
110
|
|
|
export default MenuLayout; |
|
111
|
|
|
|